package com.eds.asset.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.util.asset.SecurityUtil;

@RestController
@RequestMapping("/asset")
public class AssetAlgorithmController {

	/**
	 * Base64编码
	 * @param data
	 * @return
	 */
	@GetMapping("/encryptBase64")
    public String encryptBase64(String data)
    {
		byte[] dataArr = data.getBytes();
        return SecurityUtil.encryptBASE64(dataArr);
    }
	
	/**
	 * Base64解码
	 * @param data
	 * @return
	 */
	@GetMapping("/decryptBase64")
    public byte[] decryptBase64(String data)
    {
        return SecurityUtil.decryptBASE64(data);
    }
	
	/**
	 * DES加密
	 * @param data
	 * @return
	 */
	@GetMapping("/encryptDES")
    public String encryptDES(String data)
    {
        return SecurityUtil.encryptDes(data);
    }
	
	/**
	 * DES解密
	 * @param data
	 * @return
	 */
	@GetMapping("/decryptDES")
    public String decryptDES(String data)
    {
        return SecurityUtil.decryptDes(data);
    }
	
	/**
	 * MD5单向加密
	 * @param data
	 * @return
	 */
	@GetMapping("/encryptMD5")
    public String encryptMD5(String data)
    {
        return SecurityUtil.encryptMd5(data);
    }
	
	/**
	 * SHA加密
	 * @param data
	 * @return
	 */
	@GetMapping("/encryptSHA")
    public String encryptSHA(String data)
    {
        return SecurityUtil.encryptSHA(data);
    }
	
	/**
	 * HMAC加密
	 * @param data
	 * @return
	 */
	@GetMapping("/encryptHMAC")
    public String encryptHMAC(String data)
    {
        return SecurityUtil.encryptHMAC(data);
    }
	
	/**
	 * RSA签名
	 * @param data
	 * @param privateKey
	 * @return
	 */
	@GetMapping("/signRSA")
    public String signRSA(String data, String privateKey)
    {
        return SecurityUtil.signRSA(data, privateKey);
    }
	
	/**
	 * RSA验签
	 * @param data
	 * @param privateKey
	 * @param sign
	 * @return
	 */
	@GetMapping("/verifyRSA")
    public boolean verifyRSA(String data, String privateKey, String sign)
    {
        return SecurityUtil.verifyRSA(data, privateKey, sign);
    }
	
	/**
	 * RSA加密
	 * @param data
	 * @param privateKey
	 * @return
	 */
	@GetMapping("/encryptRSA")
    public String encryptRSA(String data, String privateKey)
    {
        return SecurityUtil.encryptRSAPrivate(data, privateKey);
    }
	
	/**
	 * RSA解密
	 * @param data
	 * @param privateKey
	 * @return
	 */
	@GetMapping("/decryptRSA")
    public String decryptRSA(String data, String privateKey)
    {
        return SecurityUtil.decryptRSAPublic(data, privateKey);
    }
	
	/**
	 * 数据库密码加密
	 * @param data
	 * @return 加密结果
	 */
	@GetMapping("/dataBasePassword")
    public String encryptDataBasePassword(String data)
    {
        return SecurityUtil.encryptPassword(data);
    }
	
}
